package com.leo;

import javafx.application.Application;
import javafx.concurrent.ScheduledService;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * @ClassName ProgressIndicatorDemo
 * @Description
 * @Author wangss
 * @date 2020.05.26 11:16
 * @Version 1.0
 */
public class ProgressIndicatorDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        ProgressIndicator progressIndicator = new ProgressIndicator();
        progressIndicator.setPrefWidth(200d);
        progressIndicator.setPrefHeight(200d);

        AnchorPane.setTopAnchor(progressIndicator, 20d);
        AnchorPane.setLeftAnchor(progressIndicator, 20d);
        anchorPane.getChildren().add(progressIndicator);

        primaryStage.setScene(scene);
        primaryStage.setTitle("combobox");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        // 另起线程任务处理进度条
        ScheduledService<Double> service = new MyScheduleService(progressIndicator);

        service.setDelay(Duration.millis(0));
        service.setPeriod(Duration.millis(1000));
        service.start();
    }
}
